﻿@model IList<Game>
<div class="page">
    <div class="pageContent">
        <div class="pageFormContent">
            <div>
                <p>
                    <label>
                        游 戏：
                    </label>
                    <select id="gameId">
                        @foreach (var o in Model)
                        {
                            <option value ="@(o.Id)">@(o.Name)</option>
                        }
                    </select>
                </p>
                <dl class="nowrap">
                    <dt style="line-height: 40px;">文 件：</dt>
                    <dd style="width: 260px;">
                        <input id="fileUpload" type="file" />
                    </dd>
                </dl>
                <div>
                </div>
                <div class="divider">
                </div>
                <div id="fileQueue">
                </div>
            </div>
        </div>
        <div class="formBar">
            <ul>
                <li>
                    <div class="buttonActive">
                        <div class="buttonContent">
                            <button type="button" onclick="javascript:$('#fileUpload').uploadify('upload','*');">
                                上 传</button></div>
                    </div>
                </li>
                <li>
                    <div class="button">
                        <div class="buttonContent">
                            <button type="button" onclick="$.pdialog.closeCurrent();">
                                取 消</button></div>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</div>
<script type="text/javascript">
    function onUploadSuccess(file, data, response) {
        if (response == true) {
            var obj = $.parseJSON(data);
            if (obj.status == true) {
                $('#fileQueue').html('<p style="color:green">' + obj.msg + '</p>');
                setTimeout(function () {
                    $.pdialog.closeCurrent();
                    navTab.reload('/game/novicecard');
                }, 2000);
            } else {
                $('#fileQueue').html('<p style="color:red">' + obj.msg + '</p>');
            }
        } else {
            $('#fileQueue').html('<p style="color:red">上传失败！</p>');
        }
    }

    $(function () {
        $('#fileUpload').uploadify({
            'swf': '/uploadify/scripts/uploadify.swf',
            'uploader': '/novicecard/upload',
            'cancelImg': '/uploadify/cancel.png',
            'scriptAccess': 'sameDomain',
            'method': 'post',
            'buttonText': '请选择文件',
            'formData': { 'gameId': $('#gameId').val() },
            'fileTypeExts': '*.txt;*.csv;',
            'fileTypeDesc': 'txt或csv文件',
            'auto': false,
            'multi': false,
            'queueID': 'fileQueue',
            'queueSizeLimit': 1,
            'fileObjName': 'filedata',
            'onUploadSuccess': onUploadSuccess,
            'onUploadError': function (file, errorCode, errorMsg, errorString) {
                alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
            }
        });
    });
</script>
